﻿// Thickness.cs
//
// Author: Luoyingliang
// Email: 731984870@qq.com
// 
// Copyright (c) 2018 Team Acoris
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Foundation
{
    /// <summary>
    /// represents a struct which indicate thickness
    /// </summary>
    public struct Thickness:IEqualityComparer<Thickness>,IEquatable<Thickness>
    {
        /// <summary>
        /// gets or sets the left value
        /// </summary>
        public float Left { get; set; }

        /// <summary>
        /// gets or set the right value
        /// </summary>
        public float Right { get; set; }

        /// <summary>
        /// gets or sets the bottom value
        /// </summary>
        public float Bottom { get; set; }

        /// <summary>
        /// gets or sets the top value
        /// </summary>
        public float Top { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool Equals(Thickness x, Thickness y) {
            return x.Left == y.Left &&
                   x.Right == y.Right &&
                   x.Bottom == y.Bottom &&
                   x.Top == y.Top;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(Thickness other) {
            var x = this;
            var y = other;
            return x.Left == y.Left &&
                   x.Right == y.Right &&
                   x.Bottom == y.Bottom &&
                   x.Top == y.Top;
        }

        public static bool operator ==(Thickness x,Thickness y) {
            return x.Left == y.Left &&
                   x.Right == y.Right &&
                   x.Bottom == y.Bottom &&
                   x.Top == y.Top;
        }

        public static bool operator !=(Thickness x,Thickness y) {
            return x.Left != y.Left ||
                   x.Right != y.Right ||
                   x.Bottom != y.Bottom ||
                   x.Top != y.Top;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int GetHashCode(Thickness obj) {
            return obj.GetHashCode();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj) {
            if(obj is Thickness y) {
                var x = this;
                return x.Left == y.Left &&
                       x.Right == y.Right &&
                       x.Bottom == y.Bottom &&
                       x.Top == y.Top;
            }

            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode() {
            return base.GetHashCode();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString() {
            return $"left:{Left},right:{Right},top:{Top},bottom:{Bottom}";
        }
    }
}
